import {post_json,get} from '../../http/axios'
export default{
    namespaced:true,
    state:{
        userInfo:{},
        avatarInfo:localStorage.getItem('avatarInfo'),
        nameInfo:localStorage.getItem('nameInfo')
    },
    getters:{},
    mutations:{
        setUserInfo(state,data){
            state.userInfo = data
        }
    },
    actions:{
        async login(context,params){
            let res = await post_json('/user/login',params)
            let token = res.data.token
            await context.dispatch('info',token)
        },
        async info(context,params){
            let res = await get('/user/info',{token:params})
            context.commit('setUserInfo',res.data);
            localStorage.setItem('token',params)
            localStorage.setItem('id',res.data['id'])
            localStorage.setItem('avatarInfo',res.data['avatar'])
            localStorage.setItem('nameInfo',res.data['name'])
        }
    }
}